package com.fang.gittest;


import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 当前项目的主启动类
 */
public class GitTestMain {

    public static final String COMPLETE_TIPS = "全部测试方法已经编写";

    public static final String SIGN_DELIVER = "-------------------------";

    public static final String NAME_CLASS_CH = "类名:";

    public static final String TEST_CLASS_TIPS = "有如下测试没有编写->";

    public static void main(String[] args) {
        /**
         * 实现功能
         *
         * 1.git status 查询编辑文件
         *
         */
        //命令行调用与解析
        CommandCallAndParse parse = new CommandCallAndParse();
        //文件解析
        FileParse fileParse = new FileParse();
        String gitStatusListStr = parse.callGitChange();

        //git status 获得更改文件列表
        List<String> path = fileParse.getGitStatusNotDelFileList(gitStatusListStr);

        HashMap<String, Set> classMethodMap = new HashMap<>();

        for (int i = 0; i < path.size(); i++) {
            Set<String> methodSet = fileParse.matchTestMethod(path.get(i));
            String pathItem = path.get(i);

            if (methodSet != null) {
                String className = pathItem;
                className = className.replace(FileParse.SUBFIX_JAVA, FileParse.EMPTY_SIGN);
                classMethodMap.put(className, methodSet);
            }
        }

        AtomicBoolean completeFlg = new AtomicBoolean(true);
        classMethodMap.forEach((s, set) -> {
            if (set.size() > 0) {
                System.out.println(SIGN_DELIVER);
                System.out.println(NAME_CLASS_CH + s);
                System.out.println(TEST_CLASS_TIPS);
                set.forEach(System.out::println);
                completeFlg.set(false);
            }
        });

        //如果发现全部添加了,给出对应的测试文件
        if (completeFlg.get()) {
            System.out.println(COMPLETE_TIPS);
        }
    }


}
